#include "tetris.h"
#include "ui_tetris.h"
#include<time.h>
#include<QMessageBox>
#include<QDebug>
#include<QPainter>
#include<QKeyEvent>

Tetris::Tetris(QWidget *parent):
    QMainWindow(parent),
    ui(new Ui::Tetris)
{
    ui->setupUi(this);
    this->setGeometry(QRect(500,150,520,800));
    //调整窗口尺寸布局；
    resize(AREA_COL*BLOCK_SIZE+MARGIN*4+4*BLOCK_SIZE,AREA_ROW*BLOCK_SIZE+MARGIN*2);
}

Tetris::~Tetris()
{
    delete ui;
}

void Tetris::paintEvent(QPaintEvent* event)
{
    //updata()或程序第一次启动时自动执行，用于画图
    QPainter painter(this);

    //画游戏背景
    //外墙
    painter.setPen(Qt::black);
    painter.setBrush(Qt::blue);
    painter.drawRect(15,35,490,730);
    //内墙
    painter.setPen(Qt::black);
    painter.setBrush(Qt::green);
    painter.drawRect(20,40,480,720);
    //画格子
    painter.setPen(Qt::yellow);
    for(int i=0;i<=24;i++)//画横线
    {
         painter.drawLine(20,i*30+40,500,i*30+40);
    }
    for(int i=0;i<=16;i++)
    {
        painter.drawLine(i*30+20,40,i*30+20,760);
    }
}